//
//  DownloadViewController.m
//  Leisure
//
//  Created by 大展 on 16/7/5.
//  Copyright © 2016年 大展. All rights reserved.
//

#import "DownloadViewController.h"

@interface DownloadViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong)UITableView *tableView;

@end

@implementation DownloadViewController


- (UITableView *)tableView {

    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:self.view.frame style:(UITableViewStylePlain)];
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}


+ (instancetype)sharedManager {

    static DownloadViewController *handle = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        handle = [[DownloadViewController alloc]init];
    });
    return handle;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"DownloadCell" bundle:nil] forCellReuseIdentifier:@"Download_cell"];
}

- (void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];
    [self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [DownloadManager sharedManager].downloadAray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    Download *download = [DownloadManager sharedManager].downloadAray[indexPath.row];
    BaseCell *cell = [FactoryMode productCellWithModel:download tableView:tableView indexPath:indexPath];

//    cell.textLabel.text = [[DownloadManager sharedManager].downloadAray[indexPath.row] title];
    // 获取正在下载的model


    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
